返回筆記列表

Claude Code × Discord 教學|用 Discord 控制 AI 寫程式(打造 AI Agent)

2026-03-21

用 Discord 控制 Claude Code — 完整設定教學

透過 Discord Bot,你可以在手機或任何裝置上用 Discord 傳訊息給 Claude Code,讓它幫你處理專案任務。


影片連結:

前置需求

安裝 Bun

Windows(PowerShell):

powershell -c "irm bun.sh/install.ps1 | iex"

安裝完成後重新開啟 PowerShell

Mac / Linux(Terminal):

curl -fsSL https://bun.sh/install | bash

安裝完成後重新開啟 Terminal


步驟一:建立 Discord Bot

  1. 前往 Discord Developer Portal
  2. 點擊右上角 New Application,輸入名稱
  3. 左側選單點 Bot
  4. 滾動到 Privileged Gateway Intents,開啟
    1. Server Member Intent
    2. Message Content Intent
    3. 儲存變更
  5. 滾動到權杖區塊,點 重設權杖,複製權杖

步驟二:邀請 Bot 加入你的 Discord 伺服器

  1. 左側選單點 OAuth2 → URL Generator
  2. Scopes 勾選 bot、applications.commands
  3. Bot Permissions 勾選以下項目:
    • 傳送訊息
    • 讀取訊息歷史記錄
    • 使用斜線命令
    • 檢視頻道
    • 附加檔案
    • 在討論串中傳送訊息
    • 新增反應
  4. 整合類型 選 Guild Install
  5. 複製下方產生的網址,開啟並將 Bot 加入你的伺服器

步驟三:在 Claude Code 安裝 Discord Plugin

在 Claude Code 對話中輸入:

/plugin install discord@claude-plugins-official

或是在 /plugin 後搜尋 discord

安裝後 重啟 claude


設定 Bot Token

在 Claude Code 對話中輸入(替換為你的 Token):

/configure 你的BotToken

這會將 Token 寫入 ~/.claude/channels/discord/.env

ex:

DISCORD_BOT_TOKEN=MTQ4NDYyMjQzMTQ2MDEzNDk4Mg.GqcE7R.l2TqV4uCYcmOgsrBcoShz7a8RoHv-JZ9ztdu1w

以參數重啟 claude

claude --channels plugin:discord@claude-plugins-official

看到以下訊息代表成功:

Listening for channel messages from: plugin:discord@claude-plugins-official

配對你的 Discord bot

  1. 在 Discord 上 DM(私訊)你的 Bot 任何內容
  2. Bot 會回傳一組 6 位配對碼
  3. 在 Claude Code 對話中輸入:
/access pair 配對碼

設定完成


步驟四:設定快捷指令(alias)

每次啟動 Claude Code 並連接 Discord,原本需要輸入這串完整指令:

claude --dangerously-skip-permissions --channels plugin:discord@claude-plugins-official

為了不用每次都輸入落落長的指令,在 PowerShell 設定一個簡短的 function。

找到你的 PowerShell profile 路徑:

$PROFILE

用記事本開啟:

notepad $PROFILE

在檔案最後加入這行並儲存:

function claude-discord { claude --dangerously-skip-permissions --channels plugin:discord@claude-plugins-official }

說明:

--dangerously-skip-permissions # 表示要用 bypass permissions mode 啟動 claude
--channels plugin:discord@claude-plugins-official # 表示啟動時要監聽 discord 的訊息

重新開啟 PowerShell 讓設定生效。

之後只需輸入 claude-discord 就等同於完整指令。


步驟五:開啟伺服器頻道支援(選用)

預設只有 DM 有效。如果你想在 Discord 伺服器的特定頻道裡操控 Claude,需要額外設定。

1. 取得頻道 ID

開啟 Discord 左下角「使用者設定 → 進階 → 開發者模式」儲存後,對想使用的頻道按右鍵 → 複製頻道 ID

2. 將該頻道加入允許清單

在 Claude Code 對話中輸入:

/access group add 頻道ID

3. 在頻道裡 @提及 Bot 來觸發

@你的Bot名稱 幫我做某件事

預設需要 @mention 才會觸發。如果不想每次都 @,可以改用:

/daccess group add 頻道ID --no-mention

取消快捷指令

如果想移除 claude-discord 指令:

notepad $PROFILE

刪除剛才加入的 function claude-discord { ... } 那一行,存檔後重開 PowerShell 即可。


注意事項